package cn.hnucm.orderservice.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 返回数据的类型
 * @author: chenjintao
 * @Date: 2021/12/7 0:29
 */
public class Result extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    private ResultCode resultCode;

    public Result(ResultCode resultCode){
        this.resultCode = resultCode;
        this.put("code",resultCode.getCode());
        this.put("msg",resultCode.getMsg());
    }

    public static Result ok(){
        return new Result(ResultCode.SUCCED);
    }

    public static Result ok(String objectName,Object object){
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put(objectName,object);
        return ok(stringObjectHashMap);
    }

    public static Result ok(Map<String,Object> map){
        Result ok = ok();
        ok.put("data",map);
        return ok;
    }

    public static Result error(ResultCode resultCode){
        return new Result(resultCode);
    }




}
